package com.neusoft.elmboot.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.elmboot.po.Wallet;
import com.neusoft.elmboot.po.WalletExc;
import com.neusoft.elmboot.service.WalletService;

@RestController
@RequestMapping("/Wallets")
public class WalletController {

	@Autowired
	private WalletService walletService;
	
	@PostMapping("/userId/{userId}/inMoney/{inMoney}")
	public Integer rechargeWallet(@PathVariable String userId, @PathVariable double inMoney) throws Exception{
		Wallet wallet = new Wallet();
		wallet.setUserId(userId);
		wallet.setBalance(inMoney);
		return walletService.rechargeWallet(wallet);
	}
	
	@PutMapping("/userId/{userId}/outMoney/{outMoney}")
	public Integer payoutWallet(@PathVariable String userId, @PathVariable double outMoney) throws Exception{
		Wallet wallet = new Wallet();
		wallet.setUserId(userId);
		wallet.setBalance(outMoney);
		return walletService.payoutWallet(wallet);
	}
	
	@PostMapping("/newUserId/{userId}")
	public Integer createWallet(Wallet wallet) throws Exception{
		return walletService.createWallet(wallet);
	}
	
	@PostMapping("/excOutUserId/{excOutUserId}/excMoney/{excMoney}/excInUserId/{exsInUserId}")
	public Integer payWallet(WalletExc walletExc) throws Exception{
		return walletService.payWallet(walletExc);
	}
	
	@GetMapping("/userId/{userId}")
	public double getBalanceById(@PathVariable String userId) throws Exception{
		return walletService.getBalanceById(userId);
	}
	
	@GetMapping("/types/userId/{userId}")
	public int getTypeById(Wallet wallet) throws Exception{
		return walletService.getTypeById(wallet.getUserId());
	}
	
	@PutMapping("/userId/{userId}/type/{type}")
	public int changeTypeById(Wallet wallet) throws Exception{
		return walletService.changeTypeById(wallet);
	}
}